package cn.neusoft.luofa603.yuejian_29.adapter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
import cn.neusoft.luofa603.yuejian_29.Global;
import cn.neusoft.luofa603.yuejian_29.R;
import cn.neusoft.luofa603.yuejian_29.activity.MasterVideoActivity;
import cn.neusoft.luofa603.yuejian_29.activity.VideoActivity;
import cn.neusoft.luofa603.yuejian_29.bean.Mastervideo;

public class MasterVideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private String degree,url;
    private int i;
    private LayoutInflater mLayoutInflater;

    public  MasterVideoAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        TextView hits;
        TextView typename;
        TextView master_video_name;
        ImageView video_pic;



        public ViewHolder(View itemView){

            super(itemView);
            typename=(TextView)itemView.findViewById(R.id.type_name);
            video_pic=(ImageView)itemView.findViewById(R.id.master_video_img);
            hits=(TextView)itemView.findViewById(R.id.hit);
            master_video_name=(TextView)itemView.findViewById(R.id.video_name);

        }
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.item_master_video,parent,false);
        return new MasterVideoAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final Mastervideo.MvideoBean entity = (Mastervideo.MvideoBean) mDataList.get(position);
        if (null==entity)
            return;
        MasterVideoAdapter.ViewHolder viewHolder = ( MasterVideoAdapter.ViewHolder) holder;

        url=entity.getUrl();
        degree=entity.getDegree();
        i = Integer.parseInt(degree);
        if (i==1){
            viewHolder.typename.setText("菜鸟");
        }else if(i==2){
            viewHolder.typename.setText("入门");
        }else {
            viewHolder.typename.setText("进阶");
        }
        viewHolder.hits.setText(entity.getHits());
        viewHolder.master_video_name.setText(entity.getMvideo_name());
        Picasso.with(mContext)
                .load(Global.PIC+entity.getThumb())
                .into(viewHolder.video_pic);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mContext, MasterVideoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("url", url);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

}
